package com.control.servlet;

import com.utils.QQUntil;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class QQCallBackServlet extends HttpServlet {

    public void init() throws ServletException {
        super.init();
    }

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String code = req.getParameter("code");
        QQUntil until= new QQUntil();
        String tokenUrl = until.getTokenUrl(code);
        String token = until.getToken(tokenUrl);
        String openIdUrl = until.getOpenIdUrl(token);
        String openId = until.getOpenId(openIdUrl);

        req.setAttribute("openId",openId);

        RequestDispatcher dispatcher = req.getRequestDispatcher("/login.do?action=qq");
        dispatcher.forward(req, resp);
    }
}
